﻿using System;
using System.Xml;
using System.Xml.XPath;
using FeedsLibrary.Feeds.Abstract;

namespace FeedsLibrary.Feeds.Atom
{
    public class AtomChannel : AbstractChannel
    {
        public AtomChannel(Uri url, Uri iconUrl, DateTime currentDay, int days, bool tagsOnly)
        {
            CurrentDay = currentDay;
            Days = days;
            TagsOnly = tagsOnly;
            LoadDocumentFromUrl( url, iconUrl );
            LoadBody( false );
        }

        protected override void LoadBody( bool update )
        {
            XmlNode n = Document;

            n = FindElement( n, "feed" );

            if (n!=null)
            {
                LoadHeader( n );
                LoadItems( n, "entry", update );
            }
            Document = null;
        }

        public override IItem GetNewItem(string domain, IXPathNavigable nodeItem, DateTime lastBuildDate)
        {
            return new AtomItem( domain, nodeItem, LastBuildDate );
        }
    }
}